<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="fullName">
        <el-input
          v-model="queryParams.fullName"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="gender">
        <el-select v-model="queryParams.gender" placeholder="请选择性别" clearable>
          <el-option
            v-for="dict in dict.type.sys_user_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="联系方式" prop="contactNumber">
        <el-input
          v-model="queryParams.contactNumber"
          placeholder="请输入联系方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门" prop="department">
        <el-input
          v-model="queryParams.department"
          placeholder="请输入部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['mes/rl:ygxx:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['mes/rl:ygxx:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['mes/rl:ygxx:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['mes/rl:ygxx:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ygxxList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="姓名" align="center" prop="fullName" />
      <el-table-column label="性别" align="center" prop="gender">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.gender"/>
        </template>
      </el-table-column>
      <el-table-column label="出生日期" align="center" prop="birthDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="年龄" align="center" prop="age" />
      <el-table-column label="婚姻状况" align="center" prop="maritalStatus" />
      <el-table-column label="联系方式" align="center" prop="contactNumber" />
<!--      <el-table-column label="紧急联系人" align="center" prop="emergencyContact" />-->
      <el-table-column label="地址" align="center" prop="address" />
      <el-table-column label="入职日期" align="center" prop="hireDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.hireDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="部门" align="center" prop="department" />
      <el-table-column label="职位/职称" align="center" prop="position" />
      <el-table-column label="级别" align="center" prop="jobLevel" />
<!--      <el-table-column label="工作类型" align="center" prop="jobType" />-->
<!--      <el-table-column label="薪酬等级" align="center" prop="salaryGrade" />-->
      <el-table-column label="身份证号" align="center" prop="idNumber" />
      <el-table-column label="教育背景" align="center" prop="educationLevel" />
      <el-table-column label="专业资格" align="center" prop="professionalQualifications" />
      <el-table-column label="工作经验" align="center" prop="workExperience" />
      <el-table-column label="技能和能力" align="center" prop="skillsAndAbilities" />
<!--      <el-table-column label="绩效评估" align="center" prop="performanceAssessment" />-->
<!--      <el-table-column label="培训记录" align="center" prop="trainingRecords" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['mes/rl:ygxx:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['mes/rl:ygxx:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改员工基本信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="85px">
        <el-form-item label="姓名" prop="fullName">
          <el-input v-model="form.fullName" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-select v-model="form.gender" placeholder="请选择性别">
            <el-option
              v-for="dict in dict.type.sys_user_sex"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="出生日期" prop="birthDate">
          <el-date-picker clearable
            v-model="form.birthDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择出生日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="婚姻状况" prop="maritalStatus">
          <el-input v-model="form.maritalStatus" placeholder="请输入婚姻状况" />
        </el-form-item>
        <el-form-item label="联系方式" prop="contactNumber">
          <el-input v-model="form.contactNumber" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="紧急联系人" prop="emergencyContact">
          <el-input v-model="form.emergencyContact" placeholder="请输入紧急联系人" />
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入地址" />
        </el-form-item>
        <el-form-item label="入职日期" prop="hireDate">
          <el-date-picker clearable
            v-model="form.hireDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择入职日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="部门" prop="department">
          <el-input v-model="form.department" placeholder="请输入部门" />
        </el-form-item>
        <el-form-item label="职位/职称" prop="position">
          <el-input v-model="form.position" placeholder="请输入职位/职称" />
        </el-form-item>
        <el-form-item label="级别" prop="jobLevel">
          <el-input v-model="form.jobLevel" placeholder="请输入级别" />
        </el-form-item>
<!--        <el-form-item label="工作类型" prop="jobType">-->
<!--          <el-select v-model="form.jobType" placeholder="请选择工作类型">-->
<!--            <el-option label="请选择字典生成" value="" />-->
<!--          </el-select>-->
<!--        </el-form-item>-->
        <el-form-item label="薪酬等级" prop="salaryGrade">
          <el-input v-model="form.salaryGrade" placeholder="请输入薪酬等级" />
        </el-form-item>
        <el-form-item label="身份证号" prop="idNumber">
          <el-input v-model="form.idNumber" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="教育背景" prop="educationLevel">
          <el-input v-model="form.educationLevel" placeholder="请输入教育背景" />
        </el-form-item>
        <el-form-item label="专业资格" prop="professionalQualifications">
          <el-input v-model="form.professionalQualifications" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="工作经验" prop="workExperience">
          <el-input v-model="form.workExperience" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="技能和能力" prop="skillsAndAbilities">
          <el-input v-model="form.skillsAndAbilities" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="绩效评估" prop="performanceAssessment">
          <el-input v-model="form.performanceAssessment" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="培训记录" prop="trainingRecords">
          <el-input v-model="form.trainingRecords" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listYgxx, getYgxx, delYgxx, addYgxx, updateYgxx } from "@/api/mes/rl/ygxx";

export default {
  name: "Ygxx",
  dicts: ['sys_user_sex'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 员工基本信息表格数据
      ygxxList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fullName: null,        gender: null,        contactNumber: null,        department: null,      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        fullName: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],        gender: [
          { required: true, message: "性别不能为空", trigger: "change" }
        ],        birthDate: [
          { required: true, message: "出生日期不能为空", trigger: "blur" }
        ],        contactNumber: [
          { required: true, message: "联系方式不能为空", trigger: "blur" }
        ],        address: [
          { required: true, message: "地址不能为空", trigger: "blur" }
        ],        hireDate: [
          { required: true, message: "入职日期不能为空", trigger: "blur" }
        ],        department: [
          { required: true, message: "部门不能为空", trigger: "blur" }
        ],        position: [
          { required: true, message: "职位/职称不能为空", trigger: "blur" }
        ],        jobLevel: [
          { required: true, message: "级别不能为空", trigger: "blur" }
        ],      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询员工基本信息列表 */
    getList() {
      this.loading = true;
      listYgxx(this.queryParams).then(response => {
        this.ygxxList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        employeeId: null,        fullName: null,        gender: null,        birthDate: null,        age: null,        maritalStatus: null,        contactNumber: null,        emergencyContact: null,        address: null,        hireDate: null,        department: null,        position: null,        jobLevel: null,        jobType: null,        salaryGrade: null,        bankAccountInfo: null,        idNumber: null,        educationLevel: null,        professionalQualifications: null,        workExperience: null,        skillsAndAbilities: null,        performanceAssessment: null,        trainingRecords: null,        createBy: null,        createTime: null,        updateBy: null,        updateTime: null      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.employeeId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加员工基本信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const employeeId = row.employeeId || this.ids
      getYgxx(employeeId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改员工基本信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.employeeId != null) {
            updateYgxx(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addYgxx(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const employeeIds = row.employeeId || this.ids;
      this.$modal.confirm('是否确认删除员工基本信息编号为"' + employeeIds + '"的数据项？').then(function() {
        return delYgxx(employeeIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('mes/rl/ygxx/export', {
        ...this.queryParams
      }, `ygxx_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
